package com.jqb.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class HttpSessions extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		/*获取Session*/
		HttpSession session = request.getSession();
		/*设置过期时间,负数表示永不过期*/
		session.setMaxInactiveInterval(30*60);
		/*是Session失效*/
//		session.invalidate();
		/*为Session设值*/
		session.setAttribute("name", "admin");
		/*到Session中取值*/
		String name = (String) session.getAttribute("name");
		System.out.println("name:"+name);
	}
}
